const app = getApp();
const Util = require('../../utils/util.js');
var Data = require("../../utils/data.js");
Page({
  data: {
    tips: '选择日期',
    date: '',
    tomorrow: '',

    autoplay: true,
    interval: 5000,
    duration: 1000,
    imgUrls:'',

    goodsList:'',
    array: [1,2,3,4],
    index: 0,
    live_number:'',

    keywords:''
  },
  imgHeight: function (e) {
    var winWid = wx.getSystemInfoSync().windowWidth; //获取当前屏幕的宽度
    var imgh = e.detail.height;//图片高度
    var imgw = e.detail.width;//图片宽度
    var swiperH = winWid * imgh / imgw + "px";
    this.setData({
      height: swiperH//设置高度
    })
  },
  doInput: function (e) {
    this.setData({
      keywords: e.detail.value
    });
  },
  //事件处理函数
  bindViewTap: function () {
    var that = this;
    var startDate = that.data.date;
    var endDate = that.data.tomorrow;
    //console.log(startDate);
    //console.log(endDate);
    wx.navigateTo({
      url: '../calender/index?startDate=' + startDate + "&endDate=" + endDate
    })
  },
  onLoad: function () {
    var startDate = this.data.startDate;
    var endDate = this.data.endDate;
    var date = Data.formatDate(new Date(), "yyyy-MM-dd");
    var tomorrow1 = new Date();
    tomorrow1.setDate((new Date()).getDate() + 1);
    var tomorrow = Data.formatDate(new Date(tomorrow1), "yyyy-MM-dd");
    if (startDate == null) {
      startDate = date;
      endDate = tomorrow;
    }
    var startD = Data.formatDate(new Date(), "MM月dd日");
    var endD = Data.formatDate(new Date(tomorrow1), "MM月dd日");

    this.setData({
      date: startDate,
      tomorrow: endDate,
      startD: startD,
      endD: endD,
      countD:1,
      startName:'今天',
      endName:'明天'
    });
    this.adList();
    this.goodsList();
  },
  onShow:function(e){
    console.info(this.data);
  },
  adList:function(){
    var that = this;
    Util.getIndex({

    },function(re){
      console.info(re);
      that.setData({
        imgUrls:re.data,
        array:re.live
      })
    })
  },
  goodsList:function(){
    var that = this;
    Util.getGoodsList({},function(ret){
      console.info(ret);
      that.setData({
        goodsList:ret.data
      });
    })
  },
  goodsDetail:function(e){
    console.info(e);
    var goods_id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: 'detail?goods_id=' + goods_id
    })
  },
  bindPickerChange:function(e){
    var that = this;
    var live = that.data.array;
    if (live[e.detail.value]>0){
      var live_number = live[e.detail.value];
    }else{
      var live_number = '';
    }
    that.setData({
      live_number: live_number,
      index: e.detail.value
    })
  },
  searchList:function(){
    var that = this;
    setTimeout(function () {
      var startDate = that.data.date;
      var endDate = that.data.tomorrow;
      var live_number = that.data.live_number;
      var keywords = that.data.keywords;
      wx.navigateTo({
        url: 'list?live_number=' + live_number + '&start_date=' + startDate + '&end_date=' + endDate + '&keywords=' + keywords
      })
    }, 300);
  },
  onShareAppMessage: function (res) {
    return {
      title: 'Hi,推荐你用用这个小程序',
      path: '/pages/index/index'
    }
  },
})
